
var keyarr=[]
// 记录用户ip
function insertkey(data,time) {
    keyarr.push(data)
    console.log(keyarr);
    let timer = setTimeout(function() {
           deletekey(data)
            clearTimeout(timer)
        }, 1000 * time) //设置有效时间50秒才能再次访问
}
// 删除用户IP
function deletekey(item) {
    let index = keyarr.findIndex((res) => {
        return res == item
    })
    keyarr.splice(index, 1);
    console.log(keyarr);
}
// 验证用户IP
function findkey(data) {
   let index=keyarr.indexOf(data)
  
   if(index<0){
       return false
   }else{
       return true
   }
}

module.exports = {
    insertkey,
    findkey,
    deletekey
}